package sr.codemg.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import sr.codemg.exception.RunException;
import sr.codemg.vm.Base;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
@Slf4j
public class GlobalExpHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Base.Response handleBizExp(HttpServletRequest request, Exception ex) {
        if (ex instanceof RunException) {
            RunException e = (RunException) ex;
            return e.getVm();
        }
        log.error("系统流程执行异常：", ex);
        return new Base.Response("9999", "系统未知错误！");
    }
}